package com.bugpool.leilema.freamwork.datascope.impl;

import com.bugpool.leilema.freamwork.datascope.DataScopeStrategy;
import com.bugpool.leilema.tc.bean.dto.DataScopeDTO;

/**
 * @Author wh
 * @Description 自定义数据权限
 * @Date 2023/6/13 15:59
 * @Version 1.0
 **/
public class CustomDataScope extends AbstractDataScope {

    @Override
    public StringBuilder sqlEnhance(DataScopeDTO dataScopeDTO) {
        StringBuilder sqlStringBuilder = dataScopeDTO.getSqlStringBuilder();
        sqlStringBuilder
                .append(" OR ")
                .append(dataScopeDTO.getTbAlias()+SUFFIX)        //主表别名
                .append("dept_id IN ( SELECT dept_id FROM tb_sys_role_dept WHERE role_id = '")
                .append(dataScopeDTO.getRoleId())
                .append("' ) ");
        return sqlStringBuilder;
    }
}
